basket.require({
	url : 'http://cdn.bootcss.com/jquery/2.1.4/jquery.min.js'
}, {
	url : "http://cdn.bootcss.com/angular.js/1.4.1/angular.min.js"
}, {
	url : "http://cdn.bootcss.com/alertify.js/0.3.11/alertify.min.js"
}, {
	url : settings.getIp() + "/peiwan-server/static/js/persistence.js"
}, {
	url : settings.getIp() + "/peiwan-server/static/js/timer.js"
}).then(ready);

function ready() {
	persistence.setNamespace("peiwan_admin");
	var peiwanAdmin = angular.module('peiwan_admin', []);
	peiwanAdmin.controller('ComplainListCtrl', [
			"$scope",
			function(s) {
				var offset = 0;
				var LIMIT = 20;
				if (!persistence.get("session")) {
					location.href = "admin_login.html";
					return;
				}
				var queryList = function() {
					ajax("/getNotHandleComplains", {
						session : persistence.get("session"),
						offset : offset,
						limit : LIMIT
					}, function(data) {
						var json = JSON.parse(data);
						if (json.status == 1) {
							location.href = "admin_login.html";
							return;
						}
						var complains = json.entity;
						for ( var i in complains) {
							var complain = complains[i];
							complain.createTime = new Date(complain.createTime)
									.format("yyyy-MM-dd hh:mm:ss");
						}
						s.$apply(function() {
							s.complains = complains;
						});
					});
				}
				queryList();
				s.handleConflict = function(complainId, isPeiwanWin) {
					ajax("/handleConflictOrder", {
						session : persistence.get("session"),
						complainId : complainId,
						isPeiwanWin : isPeiwanWin
					}, function(data) {
						var json = JSON.parse(data);
						if (json.status == 1) {
							alertify.error("帐号密码错误");
							return;
						} else if (json.status == 2) {
							alertify.error("订单状态不是冲突");
							return;
						}
						queryList();
					});
				}
			} ]);
}